import sys,os

astyle_place = os.path.dirname(os.path.abspath(__file__))

astyle_bin = '%s/astyle.exe' % astyle_place

opts = ('--mode=c --style=ansi --brackets=break --pad=oper --indent=spaces=4' +
 ' --indent-brackets --convert-tabs --indent-cases')

try:
    import mglob 
    files = mglob.expand(sys.argv[1:])
except ImportError:
    print "mglob not found; try 'easy_install mglob' for extra features"
    files = sys.argv[1:] 
    

if not files:
    print "Please specify files!"
    print mglob.globsyntax
    sys.exit()

print "Reindenting files:\n","\n".join(files)

def frames(seq, framelen):
    frame = []
    it = iter(seq)
    while 1:
        obj = it.next()
        frame.append(obj)
        if len(frame) >= framelen:
            yield frame
            frame = []

for fr in frames(files, 10): # 10 files / invocation
    os.system("%s %s %s" % ( astyle_bin, opts, " ".join( fr ) ))
    print ".",
